JS.Class('Cool.Fx.Slide', function (ui){
	var box = $(ui),
		_this = this,
		index = 0,
		hover,
		scroller = box.find('div.slide_box'),
		items = box.find('div.slide_box a');

	scroller.css('position', 'relative');
	box.hover(function (){
		hover = true;
	}, function (){
		hover = false;
	});
	box.find('.slide_next').click(function (){
		show(1);
	});
	box.find('.slide_prev').click(function (){
		show(-1);
	});
	function show(i){
		var old = index;
		index = JS.range(index+i, 0, items.length - 1, true);
		var value = items.eq(index).get(0).offsetLeft;
		scroller.stop().animate({scrollLeft: value}, Math.abs(index - old) > 2 ? 800 : 400);
	}
	this.prev = function (){
		show(-1);
	}
	this.next = function (){
		if (!hover) {
			show(1);
		}		
	}
	setInterval(this.bind('next'), 3000);
});

imports("common");

JS.ready(function (){
	Cool.Fx.Slide('div.main_slide');
	Cool.Fx.FadeSlide('div.mag_slide', 'y');
});